package cn.cloudplug.instar_ec.main.suspensionkey;

import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import cn.cloudplug.core.delegate.ScentDelegate;
import cn.cloudplug.core.index.Scent;
import cn.cloudplug.instar_ec.R;
import cn.cloudplug.instar_ec.main.GlobalObjectKeys;
import cn.cloudplug.instar_ec.main.base.InstarDelegate;
import cn.cloudplug.instar_ec.main.index.IndexDelegate;
import cn.cloudplug.instar_ec.main.tool.ToolDelegate;
import cn.cloudplug.ui.widget.SuspensionButton;
import me.yokeyword.fragmentation.ISupportFragment;

/**
 * Created by pc on 2018/2/3.
 */

public class SuspensionKeyManager {
    private ScentDelegate delegate;

    private SuspensionKeyManager(){}
    private AppCompatActivity activity;

    private List<SuspensionButton.Bean> getMenu() {
        View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int id=v.getId();
                if(id==R.id.iv_record){

                }else if(id==R.id.iv_message){

                }else if(id==R.id.iv_coordination){

                }else if(id==R.id.iv_album){

                }else if(id==R.id.iv_tool){
                    suspensionButton.close();
                    Scent.mianHandler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            delegate.getSupportDelegate().start(new ToolDelegate(), ISupportFragment.SINGLETASK);
                        }
                    },900);
                }
            }
        };
        ArrayList<SuspensionButton.Bean> menus= new ArrayList<>();
        menus.add(new SuspensionButton.Bean("录音", R.mipmap.icon_record,onClickListener, R.id.iv_record));
        menus.add(new SuspensionButton.Bean("通讯", R.mipmap.icon_message,onClickListener, R.id.iv_message));
        menus.add(new SuspensionButton.Bean("协同", R.mipmap.icon_coordination,onClickListener, R.id.iv_coordination));
        menus.add(new SuspensionButton.Bean("相册", R.mipmap.icon_album,onClickListener, R.id.iv_album));
        menus.add(new SuspensionButton.Bean("工具", R.mipmap.icon_tool,onClickListener, R.id.iv_tool));
        return menus;
    }

    public void delegate(InstarDelegate delegate) {
        this.delegate=delegate;
        if(delegate instanceof IndexDelegate){
            suspensionButton.show();
        }
    }

    private static final class Holder{
        private final static SuspensionKeyManager Instance = new SuspensionKeyManager();
    }
    private SuspensionButton suspensionButton;

    public static SuspensionKeyManager getInstance(){return Holder.Instance;}
    public void init(ScentDelegate delegate){
        this.activity= (AppCompatActivity) delegate.getActivity();
        this.delegate = delegate;
        suspensionButton = new SuspensionButton(activity, getMenu());
        suspensionButton.setImage(R.mipmap.icon_sus_man);
        suspensionButton.setMenuStateChangeListener(new SuspensionButton.MenuStateChangeListener() {
            @Override
            public void onMenuOpened() {
                suspensionButton.setImage(R.mipmap.icon_sus_blue);
            }

            @Override
            public void onMenuClosed() {
                suspensionButton.setImage(R.mipmap.icon_sus_man);
            }
        });
        Scent.put(GlobalObjectKeys.SuspensionButtonKey,suspensionButton);
    }
}
